/***************************************************************************
 创建者：华磊
 开始时间：         : 2020.12.16
 copyright            : (C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   寄存器指令属性编辑视窗
*                                                                         *
 ***************************************************************************/
#include "registerinstructionview.h"
#include "ui_registerinstructionview.h"
#include "../../programView/programview.h"


RegisterInstructionView::RegisterInstructionView(int styleId,QWidget *parent):
    QWidget(parent),
    ui(new Ui::RegisterInstructionView)
{
    ui->setupUi(this);
    initialDisplayStyle(styleId);
}

void RegisterInstructionView::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        ui->note_GBox->hide();
        ui->forward_Btn->setGeometry(10,350,70,40);
        ui->save_Btn->setGeometry(360,350,70,40);
        break;
    default:
        break;
    }
}

void RegisterInstructionView::updateView()
{
    if(EM_REGISTER_TYPE_R == selectRegisterType)
    {
        ui->R_radioButton->setChecked(true);
        ui->PL_radioButton->setChecked(false);
        ui->GR_radioButton->setChecked(false);
        ui->PR_radioButton->setChecked(false);
        ui->PRij_radioButton->setChecked(false);

        ui->RIndex_lineEdit->setText(rIndex);
        ui->R_lineEdit->setText(rValue);
    }
    else if(EM_REGISTER_TYPE_GR == selectRegisterType)
    {
        ui->GR_radioButton->setChecked(true);
        ui->R_radioButton->setChecked(false);
        ui->PL_radioButton->setChecked(false);
        ui->PR_radioButton->setChecked(false);
        ui->PRij_radioButton->setChecked(false);

        ui->GRIndex_lineEdit->setText(gRIndex);
        ui->GR_lineEdit->setText(gRValue);
    }
    else if(EM_REGISTER_TYPE_PR_I == selectRegisterType)
    {
        ui->PR_radioButton->setChecked(true);
        ui->R_radioButton->setChecked(false);
        ui->GR_radioButton->setChecked(false);
        ui->PL_radioButton->setChecked(false);
        ui->PRij_radioButton->setChecked(false);

        ui->PRIndex_lineEdit->setText(pRIndex);
        ui->PR_lineEdit->setText(pRIValue);
    }
    else if(EM_REGISTER_TYPE_PR_IJ == selectRegisterType)
    {
        ui->PRij_radioButton->setChecked(true);
        ui->R_radioButton->setChecked(false);
        ui->GR_radioButton->setChecked(false);
        ui->PR_radioButton->setChecked(false);
        ui->PL_radioButton->setChecked(false);

        ui->PRi_lineEdit->setText(iIndex);
        ui->PRj_lineEdit->setText(jIndex);
        ui->PRij_lineEdit->setText(pRIJValue);
    }
    else if(EM_REGISTER_TYPE_PL == selectRegisterType)
    {
        ui->PL_radioButton->setChecked(true);
        ui->R_radioButton->setChecked(false);
        ui->GR_radioButton->setChecked(false);
        ui->PR_radioButton->setChecked(false);
        ui->PRij_radioButton->setChecked(false);

        ui->PLIndex_lineEdit->setText(pLIndex);
        ui->PL_lineEdit->setText(plElement1);
        ui->PL_lineEdit_2->setText(plElement2);
        ui->PL_lineEdit_3->setText(plElement3);
    }

    ui->note_lineEdit->setText(note);
}

void RegisterInstructionView::getInput()
{
    if(EM_REGISTER_TYPE_R == selectRegisterType)
    {
        rIndex = ui->RIndex_lineEdit->text();
        rValue = ui->R_lineEdit->text();
    }
    else if(EM_REGISTER_TYPE_GR == selectRegisterType)
    {
        gRIndex = ui->GRIndex_lineEdit->text();
        gRValue = ui->GR_lineEdit->text();
    }
    else if(EM_REGISTER_TYPE_PR_I == selectRegisterType)
    {
        pRIndex = ui->PRIndex_lineEdit->text();
        pRIValue = ui->PR_lineEdit->text();
    }
    else if(EM_REGISTER_TYPE_PR_IJ == selectRegisterType)
    {
        iIndex = ui->PRi_lineEdit->text();
        jIndex = ui->PRj_lineEdit->text();
        pRIJValue = ui->PRij_lineEdit->text();
    }
    else if(EM_REGISTER_TYPE_PL == selectRegisterType)
    {
        pLIndex = ui->PLIndex_lineEdit->text();
        plElement1 = ui->PL_lineEdit->text();
        plElement2 = ui->PL_lineEdit_2->text();
        plElement3 = ui->PL_lineEdit_3->text();
    }
    note = ui->note_lineEdit->text();
}

void RegisterInstructionView::on_R_radioButton_clicked()
{
    emit selectRInstruction();
}

void RegisterInstructionView::on_GR_radioButton_clicked()
{
    emit selectGRInstruction();
}

void RegisterInstructionView::on_PR_radioButton_clicked()
{
    emit selectPRInstruction();
}

void RegisterInstructionView::on_PRij_radioButton_clicked()
{
    emit selectPRijInstruction();
}

void RegisterInstructionView::on_PL_radioButton_clicked()
{
    emit selectPLInstruction();
}

void RegisterInstructionView::on_clearNote_Btn_clicked()
{
    ui->note_lineEdit->clear();
    emit clearNote();
}

void RegisterInstructionView::on_forward_Btn_clicked()
{
    this->close();
    programView->instructionListFlag = 0;
    programView->editInstructionViewShowOrHide();
}

void RegisterInstructionView::on_save_Btn_clicked()
{
    getInput();

    emit finishEditInstruction();
    emit saveInstruction(instruction);
}

void RegisterInstructionView::changeLanguage(int language)
{
    if(1 == language)
    {
        translator.load("/agvwork/AgvHmi/baseBag/hmiProject/language/registerViewEnglishLan.qm");
        qApp->installTranslator(&translator);
    }
    else
    {
        qApp->removeTranslator(&translator);
    }
    ui->retranslateUi(this);
}
